import React from 'react';
import {Table, Button} from 'antd';

const {Column} = Table;

class NoteListView extends React.Component{

    handleOnEditBtnClick(e, {noteId}){
        this.props.onNoteEdit(noteId);
    }

    handleDeleteBtnClick(e, {noteId}){
        this.props.onNoteDelete(noteId);
    }

    render(){
        const pagination = {
            current: this.props.current,
            total: this.props.total,
            onChange: this.props.onChange
        };

        return(
            <Table dataSource={this.props.noteList} rowKey={note => note.noteId} pagination={pagination}>
                <Column title={'编号'} dataIndex={'noteId'}/>
                <Column title={'标题'} dataIndex={'title'}/>
                <Column title={'创建时间'} dataIndex={'createTime'}/>
                <Column title={'更新时间'} dataIndex={'updateTime'}/>
                <Column title={'操作'} render={
                    (text, record) => {
                        return <div>
                            <Button type={'primary'} size={'large'}  name={'noteId'} onClick={(e, payload) => this.handleOnEditBtnClick(e, record)}>编辑</Button>
                            <Button type={'danger'} size={'large'} onClick={(e, payload) => this.handleDeleteBtnClick(e, record)}>删除</Button>
                        </div>
                    }
                }/>
            </Table>
        )
    }

}

export default NoteListView